package portal.monitor.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import portal.monitor.dao.BlackList;
import portal.monitor.dao.BlackListExample;
import portal.monitor.dao.mapper.BlackListMapper;
import portal.monitor.service.BlackListService;

@Service
public class BlackListServiceImpl implements BlackListService {

	
	@Autowired
	BlackListMapper blackListMapper;
	
	@Override
	public int add(BlackList blacklist) {
		// TODO Auto-generated method stub
		
		return blackListMapper.insertSelective(blacklist);
	}

	@Override
	public int delete(Integer id) {
		// TODO Auto-generated method stub
		return blackListMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int update(BlackList blacklist) {
		// TODO Auto-generated method stub
		return blackListMapper.updateByPrimaryKeySelective(blacklist);
	}

	@Override
	public BlackList get(Integer id) {
		// TODO Auto-generated method stub
		
		return blackListMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<BlackList> list(BlackList blacklist) {
		// TODO Auto-generated method stub
		
		return selectBlackList(blacklist);
	}

	private List<BlackList> selectBlackList(BlackList blacklist){
		BlackListExample example = new BlackListExample();
		BlackListExample.Criteria criteria = example.createCriteria();
		if(!StringUtils.isEmpty(blacklist.getAppName())){
			criteria.andAppNameLike("%"+blacklist.getAppName()+"%");
		}
		if(!StringUtils.isEmpty(blacklist.getValid())){
			criteria.andValidEqualTo(blacklist.getValid());
		}
		
		List<BlackList> list = blackListMapper.selectByExample(example);
		
		return list;
	}


}
